#include "FileIO.h"
#include <fstream>
#include <iostream>
#include "File.h"
#include "menu.h"
using namespace std;
File *FileIO::readFromFile(string &filename)
{
    string temp;
    string s = "/home/yunlang/work/CLionProjects/TreeType/build/" + filename;
    ifstream file(s.c_str());
    if(!file)
    {
        cout << "no file" << endl;
        getchar();
        getchar();
        menu();
    }
    getline(file,temp,',');
    const string name = "name";
    const string year = "year";
    if(temp != name)
    {
    }
    getline(file,temp,'\n');
    if(temp != year)
    {
        printf("格式错误");
    }
    File * forestFile = new File();
    int i = 0;
    while( getline(file,temp,',') )
    {
        //cout << temp << endl;
        forestFile->insertTree(temp);
        getline(file, temp, '\n');
        forestFile->insertYear(temp);
    }
    return forestFile;
}
//
// Created by yunlang on 2021/12/15.
//

